package entity;

import NLP.Sentiment;

import java.util.List;

public class Word {
    // 字/词本身
    private String word;
    // 情感色彩极性
    private SentimentResult sentiment;
    // 韵母()
    private List<String> yunmu;
    // 声调(1,2,3,4)
    private List<String> tone;
    //词性(part of speech)
    private String pos;

    /**
     * 获得word的长度
     * @return
     */
    public int length(){
        return word.length();
    }

    /**
     * 因为word可能不止一个字, 返回第一个字的平仄
     * @return
     */
    public int firstTone(){
        return Integer.parseInt(tone.get(0));
    }

    /**
     * 因为word可能不止一个字, 返回最后一个字的平仄
     * @return
     */
    public int lastTone(){
        return Integer.parseInt(tone.get(tone.size()-1));
    }


    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }

    public SentimentResult getSentiment() {
        return sentiment;
    }

    public void setSentiment(SentimentResult sentiment) {
        this.sentiment = sentiment;
    }

    public List<String> getYunmu() {
        return yunmu;
    }

    public void setYunmu(List<String> yunmu) {
        this.yunmu = yunmu;
    }

    public List<String> getTone() {
        return tone;
    }

    public void setTone(List<String> tone) {
        this.tone = tone;
    }

    public String getPos() {
        return pos;
    }

    public void setPos(String pos) {
        this.pos = pos;
    }

    /**
     * 重载equals方法，只要word和pos一致就认为相等
     * @param o
     * @return
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Word word1 = (Word) o;

        if (!word.equals(word1.word)) return false;
        return pos.equals(word1.pos);
    }

    @Override
    public int hashCode() {
        int result = word.hashCode();
        result = 31 * result + pos.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Word{" +
                "word='" + word + '\'' +
                ", sentiment=" + sentiment +
                ", yunmu=" + yunmu +
                ", tone=" + tone +
                ", pos='" + pos + '\'' +
                '}';
    }
}
